package bean;

import entity.Statistique;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import session.CompteFacadeLocal;
import session.StatistiqueFacadeLocal;

@ManagedBean
@RequestScoped
public class StatistiqueBean {
    
    @EJB
    private StatistiqueFacadeLocal statistiqueBean;
    @EJB
    private CompteFacadeLocal compteBean;
    private String utilisateurSelected = "";
    private String compteSelected = "";
    private String typeSelected = "";
    private String successSelected = "";
    private String serverSelected = "";
    

    public StatistiqueBean() {
    }
    
    public List<Statistique> getAllStatistique() {
        this.getDistinctServer();
        if(this.compteSelected == null) {
            this.setCompteSelected("");
        }
        
        if(this.utilisateurSelected == null) {
            this.setUtilisateurSelected("");
        }
        
        if(this.typeSelected == null) {
            this.setTypeSelected("");
        }       
        
        if(this.serverSelected == null) {
            this.setServerSelected("");
        } 
        
        Boolean success = null;
        
        if (this.successSelected == null) {
            this.setSuccessSelected("");
        } else {
            if ("TRUE".equals(this.getSuccessSelected())) {
                success = Boolean.TRUE;
            } else if ("FALSE".equals(this.getSuccessSelected())) {
                success = Boolean.FALSE;
            } else {
                success = null;
            }
        }
        
        return statistiqueBean.findAllByFilter(utilisateurSelected, typeSelected, compteSelected, success, serverSelected);
    }
    
    public List<String> getDistinctServer() {
        for(String server : compteBean.findDistinctServer()) {
            System.out.println(server);
        }
        return compteBean.findDistinctServer();        
    }

    public String getUtilisateurSelected() {
        return utilisateurSelected;
    }

    public void setUtilisateurSelected(String utilisateurSelected) {
        this.utilisateurSelected = utilisateurSelected;
    }

    public String getCompteSelected() {
        return compteSelected;
    }

    public void setCompteSelected(String compteSelected) {
        this.compteSelected = compteSelected;
    }

    public String getTypeSelected() {
        return typeSelected;
    }

    public void setTypeSelected(String typeSelected) {
        this.typeSelected = typeSelected;
    }

    public String getSuccessSelected() {
        return successSelected;
    }

    public void setSuccessSelected(String successSelected) {
        this.successSelected = successSelected;
    }
    
    public void reset() {
        this.compteSelected = "";
        this.utilisateurSelected = "";
        this.typeSelected = "";
        this.successSelected = "";
        this.serverSelected = "";
    }

    public String getServerSelected() {
        return serverSelected;
    }

    public void setServerSelected(String serverSelected) {
        this.serverSelected = serverSelected;
    }
}
